package com.fr.base.core.list;

import com.fr.util.Utils;
import java.io.Serializable;
import java.util.Arrays;

public class IntList
  implements Cloneable, Serializable
{
  private int[] data;
  private int size;

  public IntList()
  {
    this(8);
  }

  public IntList(int paramInt)
  {
    this.size = 0;
    if (paramInt < 0)
      throw new IllegalArgumentException("Illegal Capacity: " + paramInt);
    this.data = new int[paramInt];
  }

  public int get(int paramInt)
    throws ArrayIndexOutOfBoundsException
  {
    if (paramInt >= this.size)
      throw new ArrayIndexOutOfBoundsException(paramInt);
    return this.data[paramInt];
  }

  public void set(int paramInt1, int paramInt2)
    throws ArrayIndexOutOfBoundsException
  {
    if (paramInt1 >= this.size)
      throw new ArrayIndexOutOfBoundsException(paramInt1);
    this.data[paramInt1] = paramInt2;
  }

  public void add(int paramInt)
  {
    ensureCapacity(this.size + 1);
    this.data[(this.size++)] = paramInt;
  }

  public void add(int paramInt1, int paramInt2)
  {
    if ((paramInt1 > this.size) || (paramInt1 < 0))
      throw new IndexOutOfBoundsException("Index: " + paramInt1 + ", Size: " + this.size);
    ensureCapacity(this.size + 1);
    System.arraycopy(this.data, paramInt1, this.data, paramInt1 + 1, this.size - paramInt1);
    this.data[paramInt1] = paramInt2;
    this.size += 1;
  }

  public boolean contain(int paramInt)
  {
    for (int i = 0; i < this.size; ++i)
      if (this.data[i] == paramInt)
        return true;
    return false;
  }

  public int indexOf(int paramInt)
  {
    for (int i = 0; i < this.size; ++i)
      if (this.data[i] == paramInt)
        return i;
    return -1;
  }

  public int size()
  {
    return this.size;
  }

  public void remove(int paramInt)
  {
    int i = this.size - paramInt - 1;
    if (i > 0)
      System.arraycopy(this.data, paramInt + 1, this.data, paramInt, i);
    this.size -= 1;
  }

  public void removeEqual()
  {
    int[] arrayOfInt = toArray();
    clear();
    for (int i = 0; i < arrayOfInt.length; ++i)
      if (!(contain(arrayOfInt[i])))
        add(arrayOfInt[i]);
  }

  public void sort()
  {
    trimToSize();
    Arrays.sort(this.data);
  }

  public void clear()
  {
    ensureCapacity(0);
    this.size = 0;
  }

  private void trimToSize()
  {
    this.data = toArray();
  }

  public int[] toArray()
  {
    int[] arrayOfInt = new int[this.size];
    System.arraycopy(this.data, 0, arrayOfInt, 0, this.size);
    return arrayOfInt;
  }

  public boolean addAll(int paramInt, IntList paramIntList)
  {
    if ((paramInt > this.size) || (paramInt < 0))
      throw new IndexOutOfBoundsException("Index: " + paramInt + ", Size: " + this.size);
    int[] arrayOfInt = paramIntList.toArray();
    int i = arrayOfInt.length;
    ensureCapacity(this.size + i);
    int j = this.size - paramInt;
    if (j > 0)
      System.arraycopy(this.data, paramInt, this.data, paramInt + i, j);
    System.arraycopy(arrayOfInt, 0, this.data, paramInt, i);
    this.size += i;
    return (i != 0);
  }

  public boolean addAll(IntList paramIntList)
  {
    int[] arrayOfInt = paramIntList.toArray();
    int i = arrayOfInt.length;
    ensureCapacity(this.size + i);
    System.arraycopy(arrayOfInt, 0, this.data, this.size, i);
    this.size += i;
    return (i != 0);
  }

  public int toSum()
  {
    int i = 0;
    for (int j = 0; j < this.size; ++j)
      i += get(j);
    return i;
  }

  public int toRangeSum(int paramInt1, int paramInt2)
  {
    int i = 0;
    int j = Math.min(paramInt1, paramInt2);
    int k = Math.max(paramInt1, paramInt2);
    for (int l = j; l < k; ++l)
      i += get(l);
    return ((paramInt1 <= paramInt2) ? i : -i);
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof IntList))
      return false;
    IntList localIntList = (IntList)paramObject;
    if (this.size != localIntList.size)
      return false;
    for (int i = 0; i < this.size; ++i)
      if (this.data[i] != localIntList.data[i])
        return false;
    return true;
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    IntList localIntList = (IntList)super.clone();
    localIntList.clear();
    for (int i = 0; i < size(); ++i)
      localIntList.add(get(i));
    return localIntList;
  }

  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer("[");
    int i = 0;
    int j = size();
    while (i < j)
    {
      if (i > 0)
        localStringBuffer.append(",");
      localStringBuffer.append(get(i));
      ++i;
    }
    localStringBuffer.append("]");
    return localStringBuffer.toString();
  }

  private void ensureCapacity(int paramInt)
  {
    int i = this.data.length;
    if (paramInt > i)
    {
      int[] arrayOfInt = this.data;
      int j = i * 3 / 2 + 1;
      if (j < paramInt)
        j = paramInt;
      this.data = new int[j];
      System.arraycopy(arrayOfInt, 0, this.data, 0, this.size);
    }
  }

  public static IntList asList(int[] paramArrayOfInt)
  {
    if (paramArrayOfInt == null)
      throw new NullPointerException();
    IntList localIntList = new IntList();
    localIntList.data = paramArrayOfInt;
    localIntList.size = localIntList.data.length;
    return localIntList;
  }

  public static String toStringDecimal(IntList paramIntList, char paramChar)
  {
    int i;
    StringBuffer localStringBuffer = new StringBuffer();
    if (paramIntList != null)
      for (i = 0; i < paramIntList.size(); ++i)
      {
        if (i != 0)
          localStringBuffer.append(paramChar);
        localStringBuffer.append(paramIntList.get(i));
      }
    return localStringBuffer.toString();
  }

  public static String toStringDecimal(int[] paramArrayOfInt, char paramChar)
  {
    int i;
    StringBuffer localStringBuffer = new StringBuffer();
    if (paramArrayOfInt != null)
      for (i = 0; i < paramArrayOfInt.length; ++i)
      {
        if (i != 0)
          localStringBuffer.append(paramChar);
        localStringBuffer.append(paramArrayOfInt[i]);
      }
    return localStringBuffer.toString();
  }

  public static IntList toIntListDecimal(String paramString, char paramChar)
  {
    IntList localIntList = new IntList();
    if (paramString == null)
      return localIntList;
    String[] arrayOfString1 = Utils.splitString(paramString, "" + paramChar);
    for (int i = 0; i < arrayOfString1.length; ++i)
    {
      int l;
      String str = arrayOfString1[i].trim();
      try
      {
        localIntList.add(Integer.parseInt(str));
      }
      catch (Exception localException)
      {
        String[] arrayOfString2 = Utils.splitString(str, "-");
        int j = -1;
        int k = -1;
        for (l = 0; l < arrayOfString2.length; ++l)
        {
          int i1 = 0;
          try
          {
            i1 = Integer.parseInt(arrayOfString2[l]);
          }
          catch (NumberFormatException localNumberFormatException)
          {
          }
          if (l == 0)
          {
            j = i1;
            k = i1;
          }
          else
          {
            j = Math.min(i1, j);
            k = Math.max(i1, k);
          }
        }
        for (l = j; l <= k; ++l)
          localIntList.add(l);
      }
    }
    return localIntList;
  }

  public static int[] toIntArrayDecimal(String paramString, char paramChar)
  {
    return toIntListDecimal(paramString, paramChar).toArray();
  }

  public static IntList intersectList(IntList paramIntList1, IntList paramIntList2)
  {
    if ((paramIntList1 == null) || (paramIntList2 == null))
      return null;
    int[] arrayOfInt = intersectArray(paramIntList1.toArray(), paramIntList2.toArray());
    return asList(arrayOfInt);
  }

  public static int[] intersectArray(int[] paramArrayOfInt1, int[] paramArrayOfInt2)
  {
    if (paramArrayOfInt1 == null)
      return ((paramArrayOfInt2 == null) ? paramArrayOfInt2 : (int[])paramArrayOfInt2.clone());
    if (paramArrayOfInt2 == null)
      return ((int[])paramArrayOfInt1.clone());
    int[] arrayOfInt1 = (int[])paramArrayOfInt1.clone();
    int[] arrayOfInt2 = (int[])paramArrayOfInt2.clone();
    Arrays.sort(arrayOfInt1);
    Arrays.sort(arrayOfInt2);
    IntList localIntList = new IntList();
    int i = 0;
    for (int j = 0; j < arrayOfInt1.length; ++j)
      for (int k = i; k < arrayOfInt2.length; ++k)
      {
        i = k;
        if (arrayOfInt1[j] == arrayOfInt2[k])
        {
          localIntList.add(arrayOfInt1[j]);
          break;
        }
        if (arrayOfInt1[j] < arrayOfInt2[k])
          break;
      }
    return localIntList.toArray();
  }

  public static IntList unionList(IntList paramIntList1, IntList paramIntList2)
  {
    if (paramIntList1 == null)
      return paramIntList2;
    if (paramIntList2 == null)
      return paramIntList1;
    return asList(unionArray(paramIntList1.toArray(), paramIntList2.toArray()));
  }

  public static int[] unionArray(int[] paramArrayOfInt1, int[] paramArrayOfInt2)
  {
    if (paramArrayOfInt1 == null)
      return ((paramArrayOfInt2 == null) ? paramArrayOfInt2 : (int[])paramArrayOfInt2.clone());
    if (paramArrayOfInt2 == null)
      return ((int[])paramArrayOfInt1.clone());
    int[] arrayOfInt1 = (int[])paramArrayOfInt1.clone();
    int[] arrayOfInt2 = (int[])paramArrayOfInt2.clone();
    Arrays.sort(arrayOfInt1);
    Arrays.sort(arrayOfInt2);
    IntList localIntList = new IntList();
    int i = 0;
    int j = 0;
    while (true)
    {
      do
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                if ((i >= arrayOfInt1.length) && (j >= arrayOfInt2.length))
                  break label210;
                if (i != arrayOfInt1.length)
                  break;
                localIntList.add(arrayOfInt2[j]);
                ++j;
              }
              if (j != arrayOfInt2.length)
                break;
              localIntList.add(arrayOfInt1[i]);
              ++i;
            }
            if (arrayOfInt1[i] >= arrayOfInt2[j])
              break;
            localIntList.add(arrayOfInt1[i]);
            ++i;
          }
          if (arrayOfInt1[i] <= arrayOfInt2[j])
            break;
          localIntList.add(arrayOfInt2[j]);
          ++j;
        }
      while (arrayOfInt1[i] != arrayOfInt2[j]);
      localIntList.add(arrayOfInt2[j]);
      ++i;
      ++j;
    }
    label210: return localIntList.toArray();
  }

  public static void sort(IntList paramIntList)
  {
    int[] arrayOfInt = paramIntList.toArray();
    Arrays.sort(arrayOfInt);
    paramIntList.data = arrayOfInt;
  }

  public static int[] range(int paramInt)
  {
    return range(0, paramInt);
  }

  public static int[] range(int paramInt1, int paramInt2)
  {
    return range(paramInt1, paramInt2, 1);
  }

  public static int[] range(int paramInt1, int paramInt2, int paramInt3)
  {
    IntList localIntList = new IntList();
    if (paramInt3 > 0)
      while (true)
      {
        if (paramInt1 >= paramInt2)
          break label46;
        localIntList.add(paramInt1);
        paramInt1 += paramInt3;
      }
    while (paramInt1 > paramInt2)
    {
      localIntList.add(paramInt1);
      paramInt1 += paramInt3;
    }
    label46: return localIntList.toArray();
  }
}